﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
using System.Reflection;
using UMC.Wiki.Entities;
using UMC.Web;

namespace UMC.Wiki.Activities
{
    class SubjectPortfolioSeqActivity : WebActivity
    {
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var ids = this.AsyncDialog("Id", request.Model, "Portfolio").Split(',');

            var sub = DataFactory.Instance().Portfolio(UMC.Data.Utility.UInt64Parse(ids[0]).Value);

            var user = this.Context.Token.Identity();
            ulong projectId;//= Guid.Empty;

            if (sub.project_id.HasValue)
            {
                projectId = sub.project_id.Value;

                var member = DataFactory.Instance().ProjectMember(projectId, user.Id.Value);

                if (member != null)
                {
                    switch (member.AuthType)
                    {
                        case WebAuthType.Admin:
                        case WebAuthType.User:
                            break;
                        default:
                            this.Prompt("您未有编辑此图文的权限");
                            break;
                    }

                }
                else
                {
                    this.Prompt("您未有编辑此图文的权限");
                }

            }

            for (var i = 0; i < ids.Length; i++)
            {
                DataFactory.Instance().Put(new Portfolio { Id = UMC.Data.Utility.UInt64Parse(ids[i]).Value, Sequence = i });
            }

            response.Redirect(new WebMeta().Put("msg", ids.Length));


        }

    }
}